package sistemaClassificador.algoritmoGenetico;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Torneio {

	public Torneio() {

	}

	public int girar(Populacao p, MersenneTwister geradorRandom){
		int i=0;
		int rand=0;
		double aux = 0;
		int chosen = 0 ;
	//	double total  = p.getTotalFitness();
	//	double x      = geradorRandom.nextDouble();
	//	double limite = Math.abs(x) * total;
		
		float k=7;
	//	k = p.size()/4;
////		 System.out.println("P>SIZE "+p.size());
//	    System.out.println("K "+k);
	//    k = Math.round(k);
	//    List<Regra> regras_torneio = new ArrayList<Regra>();	
//	    System.out.println("K "+k);
		for(i=0;i<k;i++){
			try {
				rand = geradorRandom.nextInt(p.size());
	//			System.out.println("Rand "+rand+"Fitness"+p.getRegra(rand).getFitness());
				if(p.getRegra(rand).getFitness()>aux){
					aux = p.getRegra(rand).getFitness();
					chosen = rand;
				  }
				} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		
	//	if(i==0) {
	//		System.out.println("limite = "+limite + " total = "+ total + " i = "+i);
			
		//	return i;
	//	}
	//	i--;
	//	System.out.println("limite = "+limite + " total = "+ total + " i = "+i);
//		System.out.println("Chosen "+chosen);
		return chosen;
	}

}